//
//  LMTabBarViewController.m
//  LaboratoryManage
//
//  Created by DavidHuang on 16/8/29.
//  Copyright © 2016年 黄栋炜. All rights reserved.
//

#import "LMTabBarViewController.h"
#import "LMHomeViewController.h"
#import "LMMeViewController.h"
#import "LMNavigationController.h"
typedef enum {
    TabBarItemTypeHome,
    TabBarItemTypeMe
}TabBarItemType;

@interface LMTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation LMTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupAllChildViewControllers];
    self.delegate = self;
}

- (void)setupAllChildViewControllers {
    
    LMHomeViewController *homeVc = [[LMHomeViewController alloc] init];
    [self setupChildViewController:homeVc title:@"首页" imageName:@"user_tab_home_nor" selectedImageName:@"user_tab_home_h"];
    homeVc.tabBarItem.tag = TabBarItemTypeHome;
    
//    JZLoanViewController *loanVc = [[JZLoanViewController alloc] init];
//    [self setupChildViewController:loanVc title:@"贷款" imageName:@"user_tab_credit_nor" selectedImageName:@"user_tab_credit_h"];
//    loanVc.tabBarItem.tag = UserNormalControllerLoan;
//    
//    JZTalkContentViewController *talkListVc = [[JZTalkContentViewController alloc] init];
//    [self setupChildViewController:talkListVc title:@"沟通" imageName:@"user_tab_chat_nor" selectedImageName:@"user_tab_chat_h"];
//    talkListVc.tabBarItem.tag = UserNormalControllerTalk;
    
    LMMeViewController *meVc = [[LMMeViewController alloc] init];
    [self setupChildViewController:meVc title:@"我的" imageName:@"user_tab_me_nor" selectedImageName:@"user_tab_me_h"];
    meVc.tabBarItem.tag = TabBarItemTypeMe;
    
    [[UITabBarItem appearance] setTitleTextAttributes:                                                         [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorOfLightBlueColor],NSForegroundColorAttributeName, nil]forState:UIControlStateSelected];
}
- (void)setupChildViewController:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName {
    // 1.设置控制器的属性
    childVc.title = title;
    // 设置图标
    childVc.tabBarItem.image = [UIImage imageNamed:imageName];
    // 设置选中的图标
    UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
    childVc.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 2.包装一个导航控制器
    LMNavigationController *nav = [[LMNavigationController alloc] initWithRootViewController:childVc];
    [self addChildViewController:nav];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
//    if ((viewController.tabBarItem.tag == TabBarItemTypeHome || viewController.tabBarItem.tag == TabBarItemTypeMe) && ![UserDefaults_LoginStats integerValue]) {
//
//        JZLoginViewController *loginVc = [[JZLoginViewController alloc] init];
//        JZLoginNavigationViewController *loginNav = [[JZLoginNavigationViewController alloc] initWithRootViewController:loginVc];
//        [self presentViewController:loginNav animated:YES completion:nil];
//        return NO;
//    } else {
//        return YES;
//    }
    
};

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
